home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / PowerPlant / LDelayedTask / LTask.cp < prev    next >
Encoding:
Text File  |  1995-08-28  |  3.2 KB  |  142 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //        • LTask.cp                    © 1995, Éric Forget. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    ************************************************************************
  6. //    *                                                                      *
  7. //    *    Before using this code you should read the "License Agreement"     *
  8. //    *    document and agree with it.                                        *
  9. //    *                                                                      *
  10. //    ************************************************************************
  11. //
  12. //    LTask is an abstract class for dealing with task to be done.
  13. //    To see example of LTask subclass look at:
  14. //
  15. //        LDelayedTask, LNotificationTask, LTimerTask or LVerticalRetraceTask
  16. //
  17. // ---------------------------------------------------------------------------
  18. //
  19. //    Usage Notes:
  20. //    -----------
  21. //
  22. //    When creating a derived class, you should override at minimum:
  23. //
  24. //            StartTaskSelf();
  25. //            ExecuteTaskSelf();
  26. //            StopTaskSelf();
  27. //
  28. // ---------------------------------------------------------------------------
  29.  
  30.  
  31. #include    "LTask.h"
  32.  
  33. #include    "UDeleteTaskQueue.h"
  34.  
  35.  
  36. // ---------------------------------------------------------------------------
  37. //        • LTask
  38. // ---------------------------------------------------------------------------
  39.  
  40. LTask::LTask()
  41. {
  42.     mFirstDelay            = 0;
  43.     mNextDelay            = 0;
  44.     mDeleteOnCompletion    = false;
  45.     mIsExecuting        = false;
  46. }
  47.  
  48.  
  49. // ---------------------------------------------------------------------------
  50. //        • LTask
  51. // ---------------------------------------------------------------------------
  52.  
  53. LTask::LTask(
  54.     Int32    inFirstDelay,
  55.     Int32    inNextDelay,
  56.     Boolean inDeleteOnCompletion)
  57. {
  58.     mFirstDelay            = inFirstDelay;
  59.     mNextDelay            = inNextDelay;
  60.     mDeleteOnCompletion    = inDeleteOnCompletion;
  61.     mIsExecuting        = false;
  62. }
  63.  
  64.  
  65. // ---------------------------------------------------------------------------
  66. //        • ~LTask
  67. // ---------------------------------------------------------------------------
  68.  
  69. LTask::~LTask()
  70. {
  71.     
  72. }
  73.  
  74.  
  75. // ---------------------------------------------------------------------------
  76. //        • StartTask
  77. // ---------------------------------------------------------------------------
  78.  
  79. void
  80. LTask::StartTask()
  81. {
  82.     if(!IsExecuting()) {
  83.     
  84.         StartTaskSelf();
  85.         
  86.         mIsExecuting = true;
  87.         
  88.         if(mDeleteOnCompletion) {
  89.             
  90.             UDeleteTaskQueue::AddTask(this);
  91.         }
  92.     }
  93. }
  94.  
  95.  
  96. // ---------------------------------------------------------------------------
  97. //        • StopTask
  98. // ---------------------------------------------------------------------------
  99.  
  100. void
  101. LTask::StopTask()
  102. {
  103.     if(IsExecuting()) {
  104.     
  105.         mIsExecuting = false;
  106.         
  107.         StopTaskSelf();
  108.     }
  109. }
  110.  
  111.  
  112. // ---------------------------------------------------------------------------
  113. //        • ExecuteTask
  114. // ---------------------------------------------------------------------------
  115.  
  116. void
  117. LTask::ExecuteTask()
  118. {
  119.     Boolean        isLastCall = false;
  120.     
  121.     
  122.     ExecuteTaskSelf(isLastCall);
  123.     
  124.     if(!isLastCall) {
  125.     
  126.         ContinueTask();
  127.     
  128.     } else {
  129.     
  130.         StopTask();
  131.     }    
  132. }
  133.  
  134.  
  135. // ---------------------------------------------------------------------------
  136. //        • ContinueTask
  137. // ---------------------------------------------------------------------------
  138.  
  139. void
  140. LTask::ContinueTask()
  141. {
  142. }